import { setToken, getToken } from '@/libs/util'

export default {
  state: {
    username: '',
    userId: '',
    token: getToken(),
    access: '',
  },
  mutations: {
    setUserId (state, id) {
      state.userId = id
    },
    setUsername (state, name) {
      state.username = name
    },
    setAccess (state, access) {
      state.access = access
    },
    setToken (state, token) {
      console.log(token);
      state.token = token
      setToken(token)
    }
  },
  actions: {
    // 登陆
    signIn(info) {
      console.log(info);
      commit('setUserId', info.userId)
      commit('setUsername', info.username)
      commit('setAccess', info.access)
      commit('setToken', info.token)
    },

    // 退出
    signOut() {
      commit('setToken', '')
    },
  }
}
